package vg.modules.notepad;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Observable;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import vg.configuration.SimpleConfiguration;
import vg.core.AMenuItem;
import vg.core.VisualGraph;
import vg.core.event.AUIEvent;
import vg.core.event.UIEventCloseAIF;
import vg.core.event.UIEventCreateNewConnection;
import vg.core.event.UIEventDeleteConnection;
import vg.core.exception.PluginException;
import vg.core.plugin.IPlugin;
import vg.core.plugin.PluginParameter;
import vg.core.request.AUIRequest;
import vg.core.request.UIRequestGoToInAIF;
import vg.core.request.UIRequestLoadProject;
import vg.core.request.UIRequestSaveProject;
import vg.logging.FileLog;
import vg.logging.SimpleLog;
import vg.logging.WindowMessage;
import vg.model.SQLite4JavaModel;
import vg.progress.SimpleProgressManager;
import vg.userInterface.SwingUserInterface;
import vg.userInterface.utilPlugins.GraphLayoutManager;
import vg.userInterface.utilPlugins.LookAndFeelChanger;
/**
* Plugin realizes notepad for reading files.
* @author tzolotuhin
*/
public class NotepadPlugin implements IPlugin {
// Data
private PluginParameter parameter; // plugin parameter
// Components
private JMenuItem jMenuItem;
private Notepad notepad;
/**
* @see IPlugin
*/
public void install(final PluginParameter param) throws PluginException {
this.parameter = param;
this.notepad = new Notepad(param);
this.jMenuItem = new JMenuItem("Notepad");
this.jMenuItem.setIcon(new ImageIcon("./data/resources/textures/notepad/notepad_2.png"));
this.jMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
notepad.open();
}
});
this.jMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK));
this.parameter.userInterface.addMenuItem(new AMenuItem(this.jMenuItem) {
public void update(Observable o, Object arg) {
if(arg instanceof AUIEvent) {
final AUIEvent event = (AUIEvent)arg;
switch (event.getType()) {
case DEF_CLOSE_PROGRAM: {
notepad.close();
break;
}
case DEF_CHANGE_UI_STYLE: {
notepad.updateUITheme();
break;
}
case DEF_CLOSE_AIF: {
notepad.closeAIF((UIEventCloseAIF)event);
break;
}
case DEF_CREATE_NEW_CONNECT: {
notepad.addConnection((UIEventCreateNewConnection)event);
break;
}
case DEF_DELETE_CONNECT: {
notepad.deleteConnection((UIEventDeleteConnection)event);
break;
}
case DEF_RESET: {
notepad.reset();
break;
}
}
} else if(arg instanceof AUIRequest){
final AUIRequest request = (AUIRequest)arg;
switch(request.getType()) {
case DEF_GOTO_IN_AIF: {
notepad.goToAIF((UIRequestGoToInAIF)request);
break;
}
case DEF_SAVE_PROJECT: {
notepad.saveProject(((UIRequestSaveProject)request).getPath());
break;
}
case DEF_LOAD_PROJECT: {
notepad.loadProject(((UIRequestLoadProject)request).getPath());
break;
}
}
}
}
}, "edit");
}
public static void main(String[] args) {
try {
VisualGraph.setLog(new FileLog());
} catch (Throwable ex) {
ex.printStackTrace();
VisualGraph.setLog(new SimpleLog());
}
VisualGraph.setWindowMessage(new WindowMessage());
VisualGraph.setConfiguration(SimpleConfiguration.getInstance());
VisualGraph.setProgressManager(new SimpleProgressManager());
try {
VisualGraph.run();
SQLite4JavaModel model = new SQLite4JavaModel();
GraphLayoutManager layoutManager = new GraphLayoutManager();
SwingUserInterface view = new SwingUserInterface(model, "Welcome to Visual Graph", layoutManager);
PluginParameter param = new PluginParameter(model, view);
// adding system functions--------
new NotepadPlugin().install(param);
new LookAndFeelChanger().install(param);
} catch (Throwable ex) {
ex.printStackTrace();
}
}
}